/*


   Created by tys 2020/5/14.


 */

/*

      全局消息总线 Event_Bus：
      类似于原生的广播+监听机制

 */

import 'package:event_bus/event_bus.dart';

class GlobalEventBus{
  EventBus event;
  factory GlobalEventBus() => _getInstance();

  static GlobalEventBus get instance => _getInstance();

  static GlobalEventBus _instance;

  GlobalEventBus._internal() {
    // 创建对象
    event = EventBus();
  }

  static GlobalEventBus _getInstance() {
    if (_instance == null) {
      _instance = GlobalEventBus._internal();
    }
    if(_instance.event.streamController.isClosed){
      _instance = null;
      _instance = GlobalEventBus._internal();
    }
    return _instance;
  }
}
